define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: Config.php_self + location.search,
                    add_url: 'official/official_list_table/add/ids/' + Config.ids,
                    edit_url: 'official/official_list_table/edit',
                    del_url: 'official/official_list_table/del',
                    multi_url: 'official/official_list_table/multi',
                    import_url: 'official/official_list_table/import',
                    table: 'official_list_table',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'official_category', title: __('Official_category_id'),formatter: function (val,data) {
                                var id = '(ID:'+val.id+') ';
                                var language = data.language == 1?val.e_name:val.name;//英文栏目名称//中文栏目名称
                                return id + language;
                        }},
                        {field: 'official_category.name', title: __('Official_category_id')},
                        {field: 'job_title', title: __('Job_title'), operate: 'LIKE'},
                        {field: 'recruiting_numbers', title: __('Recruiting_numbers'), operate: 'LIKE'},
                        //{field: 'validity', title: __('Validity'), operate: 'LIKE'},
                        //{field: 'educational_requirements', title: __('Educational_requirements'), operate: 'LIKE'},
                        {field: 'gender', title: __('Gender'), searchList: {"0":__('Gender 0'),"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.normal},
                        {field: 'age', title: __('Age'), operate: 'LIKE'},
                        //{field: 'salary', title: __('Salary'), operate: 'LIKE'},
                        //{field: 'language_requirement', title: __('Language_requirement'), operate: 'LIKE'},
                        //{field: 'workplace', title: __('Workplace'), operate: 'LIKE'},
                        //{field: 'language', title: __('Language'), searchList: {"1":__('Language 1'),"2":__('Language 2')}, formatter: Table.api.formatter.normal},
                        //{field: 'message', title: __('Message'), operate: 'LIKE'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        //{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('To apply for the list'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('To apply for the list'),
                                    title: __('To apply for the list'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    extend: 'data-area=\'["100%", "800px"]\'',
                                    url: 'official/official_list_form/index',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'official/official_list_table/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'official/official_list_table/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'official/official_list_table/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});